package com.ant.cn;

import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Scanner;

/**
 * Created by baichuan on 2016/11/7.
 */
public class AntTest {

    private String path = "c:/start/temp.txt";

    public static void main(String[] args) {

        AntTest ant = new AntTest();

        try {
            ant.ant1();
            System.out.println("*****************************");
            ant.test001();
            System.out.println("*****************************");
            ant.test002();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void test001() throws IOException {
        FileInputStream fin=new FileInputStream(new File(path));
        System.out.println(IOUtils.toString(fin));
    }

    public void ant1() throws IOException {
        FileInputStream fin = new FileInputStream(new File(path));
        Scanner scanner = new Scanner(fin, "UTF-8");
        String text = scanner.useDelimiter("\\a").next();
        fin.close();
        System.out.println(text);
    }

    public void test002() throws IOException {

        byte[] bytes= Files.readAllBytes(Paths.get(path));
        System.out.println(new String(bytes));
    }

}
